package com.wsc.wisdomchinaqinghe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchinaqinghe.R;
import com.wsc.wisdomchinaqinghe.Tools.Tools;
import com.wsc.wisdomchinaqinghe.javaBean.MessageListBean;

import java.util.List;

/**
 * Created by Administrator on 2017/2/27 0027.
 */

public class Message_Adapter extends BaseAdapter{
    private Context context;
    private List<MessageListBean> list;

    public Message_Adapter(Context context, List<MessageListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Louyu_holder holder=null;
        View view=convertView;
        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.messagae_item,null);
            holder= new Louyu_holder(view);
            view.setTag(holder);
        }else {
            holder= (Louyu_holder) view.getTag();
        }

        MessageListBean messageListBean=list.get(position);
//        String time=Tools.formatDateTimeyyyyMMDDhhmm(Tools.formatData(list.get(position).getCreateDate()));
        holder.tv_title.setText(messageListBean.getTitle());
        String Begin_date = Tools.timedate(String.valueOf(list.get(position).getCreateDate()/1000));
        holder.tv_streetandtime.setText(messageListBean.getStreetName()+" "+Begin_date);
        Glide.with(context).load(messageListBean.getImg()).into(holder.iv_src);
        return view;
    }

    public class Louyu_holder  {
        ImageView iv_src;
        TextView tv_streetandtime, tv_title;

        public Louyu_holder(View itemView) {
            iv_src = (ImageView) itemView.findViewById(R.id.iv_src);
            tv_streetandtime = (TextView) itemView.findViewById(R.id.tv_streetandtime);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
}
